package com.neuedu.service.impl;

import com.neuedu.dao.AddDeptmentDao;
import com.neuedu.dao.DeptClassityDao;
import com.neuedu.dao.TableDao;
import com.neuedu.dao.UserDao;
import com.neuedu.factory.ClassFactory;
import com.neuedu.service.UserService;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class UserServiceImpl implements UserService {
    @Override
    public int userUpdate(Object[] objs) {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        int flag = ud.updateUser(objs);
        return flag;
    }

    @Override
    public List<Map<String, Object>> userGet(Object[] objs) {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        int pageSize = (int) objs[1];
        int pageNum = (int) objs[0];
        pageNum = (pageNum - 1) * pageSize;
        objs = new Object[]{pageNum, pageSize};
        List<Map<String, Object>> list = ud.getUser(objs);
        return list;
    }

    @Override
    public int getCount() {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        int count = ud.getCount();
        return count;
    }

    @Override
    public int deltype(Object[] objs) {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        int flag = ud.deleteUser(objs);
        return flag;
    }

    @Override
    public int addUser(Object[] objs) {
        UserDao add = (UserDao) ClassFactory.createObj("UserDao");
        return add.addUser(objs);
    }

    @Override
    public List<Map<String, Object>> likeQuery(Object[] objs) {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        String sql = "SELECT * FROM `user` where name like ? OR loginname like ?";
        return ud.getLikeUser(sql, objs);
    }

    @Override
    public List<Map<String, Object>> userGetByDept(Object[] objs) {
        UserDao ud = (UserDao) ClassFactory.createObj("UserDao");
        int pageSize = (int) objs[1];
        int pageNum = (int) objs[0];
        int deptid = (int) objs[2];
        pageNum = (pageNum - 1) * pageSize;
        objs = new Object[]{deptid, pageNum, pageSize,};
        List<Map<String, Object>> list = ud.userGetByDept(objs);
        for (Map<String, Object> map : list) {
            map.put("checkbox", "");
            map.put("checkeds", "");
        }
        return list;
    }
}
